<template>
    <div>
        <!--查询条件start --111s-->
        <el-form :inline="true" :model="query" class="query-form" size="small">
            <el-form-item>
                <el-button type="primary" icon="el-icon-edit" @click.native="showDialogAddOrEdit(null,null)">添加
                </el-button>
            </el-form-item>

            <el-form-item class="query-form-item">
                <el-input
                    v-model="query.discountid"
                    placeholder="请输入优惠券编号"
                    prefix-icon="el-icon-search"
                    @keyup.enter.native="onSubmit"
                    clearable
                ></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-refresh" @click="onRest"></el-button>
                <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
            </el-form-item>

        </el-form>
        <!--查询条件end-->
        <!--列表start --222s-->
        <el-table
            ref="multipleTable"
            v-loading="loading"
            :data="list"
            :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
            @selection-change="handleSelectionChange"
            border
        >
            <el-table-column type="selection" width="50" fixed/>
            <el-table-column label="优惠券编号ID" prop="discountid" width="80" align="center"/>

            <el-table-column label="优惠类型" prop="discounttype" align="center" width="150">
                <template slot-scope="scope">
                    <span>{{ scope.row.discounttype==0?'满减券':'现金券'}}</span>
                </template>
            </el-table-column>

            <el-table-column label="面额(元)" prop="denomination" align="center" width="150"/>
<!--            <el-table-column label="限额(元)" prop="quota" align="center" width="150"/>-->
            <el-table-column label="发放形式" prop="usemodality" align="center" width="150">
                <template slot-scope="scope">
                    <span>{{ scope.row.usemodality==0?'普通':'注册'}}</span>
                </template>
            </el-table-column>

            <el-table-column label="发放数量" prop="discountnum" align="center" width="150">
            </el-table-column>
            <el-table-column label="领取状态" prop="hasget" align="center" width="150"/>
            <el-table-column label="使用状态" prop="hasuse" align="center" width="150"/>

            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button
                        type="primary"
                        size="mini"
                        @click.native="showForm(scope.$index, scope.row)"
                    >赠送优惠券
                    </el-button>
                    <el-button
                        type="primary"
                        size="mini"
                        @click.native="detailForm(scope.$index, scope.row)"
                    >查看
                    </el-button>
                    <el-button
                        type="danger"
                        size="mini"
                        @click.native="handleDel(scope.row.discountid)"
                    >删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--列表end --222e-->

        <!--全选删除start-->
        <div class="left-container">
            <el-button type="danger" size="small" @click="delGroup()">删除已选</el-button>
            <transition name="el-fade-in-linear">
                <el-button size="small" @click="toggleSelection()" v-show="cancelToggle">取消选择</el-button>
            </transition>
        </div>
        <!--全选删除end-->

        <!--分页模块start-->
        <el-pagination
            class="pagination-container"
            background
            :page-size="query.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            layout="total,sizes,prev, pager, next, jumper"
            :current-page="query.currentPage"
            :page-sizes="[10, 20, 30, 50]"
            :total="totalNumber"
        ></el-pagination>
        <!--分页模块end-->

        <!--送券start--333s-->
        <el-dialog
            title="选择发券用户"
            :visible.sync="dialogUser"
            v-loading="userloading"
            width="60%"
            :before-close="hideDialogUser">
            <el-form :model="formData" :rules="userRules" ref="userRuleForm" label-width="100px" class="demo-ruleForm">

                <el-form-item class="query-form-item">

                    <div style="margin-left: 20px; width: 700px">
                        <el-input style="width: 500px"
                                  v-model="query3.content"
                                  placeholder="请输入手机号"
                                  prefix-icon="el-icon-search"
                                  clearable
                        ></el-input>
                        <el-button type="primary"  icon="el-icon-refresh" @click="onRest4"></el-button>
                        <el-button type="primary" icon="el-icon-search" @click="getUserList">查询</el-button>
                    </div>

                </el-form-item>

                <el-form-item >
                    <el-checkbox-group v-model="checklist" style="width: 100%;display: inline-grid;">
                        <el-checkbox style="margin-left: 30px" v-for="(item,index) in userlist" :key="index" :label="item.userid">
                            {{item.usernick}}
                        </el-checkbox>
                    </el-checkbox-group>

                </el-form-item>
                <!--分页模块start-->
                <el-pagination
                    class="pagination-container"
                    background
                    :page-size="query3.pageSize"
                    @size-change="handleSizeChange3"
                    @current-change="handleCurrentChange3"
                    layout="total,sizes,prev, pager, next, jumper"
                    :current-page="query3.currentPage"
                    :page-sizes="[10, 20, 30, 50]"
                    :total="totalNumber3"
                ></el-pagination>

            </el-form>
            <span slot="footer" class="dialog-footer">
            <el-button @click="dialogUser = false">取 消</el-button>
            <el-button type="primary" :loading="formSumbitLoding" @click="formSumbit3">赠送</el-button>
          </span>
        </el-dialog>

        <!--新增/编辑弹框start--333s-->
        <el-dialog
            :title="dialogAddOrEditName"
            :visible.sync="dialogAddOrEdit"
            width="50%"
            :before-close="hideDialogAddOrEdit">
            <el-form :model="formData" :rules="rules" ref="ruleForm" label-width="150px" class="demo-ruleForm">
                <el-form-item>
                    <el-select v-model="formData.discounttype" label="优惠券类型" placeholder="请选择"
                               clearable>
                        <el-option label="满减券" value='0'></el-option>
                        <el-option label="现金券" value='1'></el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="面额" prop="denomination">
                    <el-input v-model="formData.denomination"></el-input>
                </el-form-item>
                <el-form-item label="限额" prop="quota">
                    <el-input v-model="formData.quota"></el-input>
                </el-form-item>

                <el-form-item label="领取有效时间">
                    <el-date-picker
                        v-model="createTime"
                        type="datetimerange"
                        :picker-options="pickerOptions"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        align="left"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        :default-time="['00:00:00','23:59:59']"
                        @change="dateChange"
                    ></el-date-picker>
                </el-form-item>
                <el-form-item label="使用有效时间">
                    <el-select v-model="formData.usetimetype" placeholder="请选择" clearable>
                        <el-option
                            label="绝对时间"
                            value='0'>
                        </el-option>
                        <el-option
                            label="相对时间"
                            value='1'>
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item v-if="formData.usetimetype==='0'" label="绝对时间">
                    <el-date-picker
                        v-model="createTime1"
                        type="datetimerange"
                        :picker-options="pickerOptions"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        align="left"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        :default-time="['00:00:00','23:59:59']"
                        @change="dateChange1"
                    ></el-date-picker>
                </el-form-item>
                <el-form-item v-if="formData.usetimetype==='1'" label="相对时间" prop="delaydays">
                    <label>领取后</label>
                    <el-input v-model="formData.delaydays" type="number" style="width: 100px"></el-input>
                    <label>天有效</label>
                </el-form-item>
                <el-form-item label="发放数量" prop="discountnum">
                    <el-input v-model="formData.discountnum"></el-input>
                </el-form-item>

                <el-form-item label="发放形式">
                    <el-select v-model="formData.usemodality" placeholder="请选择" clearable :change="changes()">
                        <el-option
                            label="公开"
                            value=0>
                        </el-option>
                        <el-option
                            label="首次注册"
                            value=1>
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item label="添加使用商品" prop="mchecked">

                    <template>
                        <!-- `checked` 为 true 或 false -->
                        <el-checkbox @click="changecheck()" style="float: left" v-model="mchecked">全部商品</el-checkbox>
                        <div v-if="!mchecked" style=" width: 200px;float: left;margin-left: 20px">
                            <el-button type="primary" @click.native="goodadd()">添加商品</el-button>
                            <label>已选择{{commodityids===""?0:commodityids.split(",").length}}个商品</label>
                        </div>

                    </template>

                </el-form-item>

                <el-form-item v-if="!mchecked" label="添加使用分类" prop="userpassword">

                    <template style="float: left">
                        <div style="width: 120px">
                            <el-button style="float: left" type="primary" @click.native="goodCategory()"> 添加分类
                            </el-button>
                        </div>
                        <el-form-item label="一级分类">

                            <el-select style="width: 120px" v-model="formData.topcategoryid" placeholder="请选择"
                                       :change="topchange()">
                                <el-option
                                    v-for="(item,index) in category"
                                    :key="index"
                                    :label="item.topcategoryname"
                                    :value="item.topcategoryid">
                                </el-option>
                            </el-select>
                            <label>二级分类</label>
                            <el-select style="width: 120px" v-model="formData.secondarycategoryid" placeholder="请选择"
                                       clearable :change="secondchange()">
                                <el-option
                                    v-for="(item,index) in busCommoditySecondaryCategoryList"
                                    :key="index"
                                    :label="item.secondarycategoryname"
                                    :value="item.secondarycategoryid">
                                </el-option>
                            </el-select>

                            <label>三级分类</label>
                            <el-select style="width: 120px" v-model="formData.thirdcategoryid" placeholder="请选择"
                                       clearable>
                                <el-option
                                    v-for="(item,index) in busCommodityThirdCategoryList"
                                    :key="index"
                                    :label="item.thirdcategoryname"
                                    :value="item.thirdcategoryid">
                                </el-option>
                            </el-select>


                        </el-form-item>

                    </template>

                </el-form-item>

                <el-form-item v-if="!mchecked">
                    <template>
                        <el-table
                            ref="multipleTable"
                            :data="mlist"
                            :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
                            border
                        >
                            <el-table-column label="序号" align="center" width="50" prop="id">
                            </el-table-column>
                            <el-table-column label="分类" align="center" width="600" prop="name">
                            </el-table-column>
                            <el-table-column label="操作" align="center">
                                <template slot-scope="scope">
                                    <el-button type="danger" size="mini" @click.native="mhandleDel(scope.row.id)">删除
                                    </el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </template>
                </el-form-item>

            </el-form>
            <span slot="footer" class="dialog-footer">
    <el-button @click="dialogAddOrEdit = false">取 消</el-button>
    <el-button type="primary" :loading="formSumbitLoding" @click="formSumbit">提交</el-button>
  </span>
        </el-dialog>


        <el-dialog
            :title="formMap[formName]"
            :visible.sync="userVisible"
            :close-on-click-modal="false"
            width="1000px"
            top="5vh"
            v-dialogDrag>
            <div>
                <getGoods @on-select="selectids"></getGoods>
            </div>

        </el-dialog>

        <!--查看弹框-->
        <el-dialog
            :title="formMap[formName]"
            :visible.sync="detailVisible"
            :before-close="hideDetailForm"
            width="1000px"
            top="5vh"
            v-dialogDrag
        >
            <el-form :model="formData" label-width="140px">
                <el-form-item label="平台优惠券类型:">
                    <!--  <input v-model="formData.discounttype" type="text" readonly>-->
                    <!-- <span >{{formData.discounttype===0?'满减':'现金券'}}</span>-->
                    <span v-if="formData.discounttype===0">满减</span>
                    <span v-if="formData.discounttype===1">现金券</span>
                </el-form-item>
                <!-- <el-form-item label="优惠券编号:" >
                     <input v-model="formData.usernick" type="text" readonly>
                 </el-form-item>-->

                <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">
                    <el-form-item label="面额:" style="width:30%;display: inline-block;">
                        <input v-model="formData.denomination" type="text" readonly>
                    </el-form-item>
                    <el-form-item label="限额:" style="margin-left:80px;width:30%;display: inline-block;">
                        <input v-model="formData.quota" type="text" readonly>
                    </el-form-item>
                </el-form-item>

                <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">

                    <el-form-item label="领取开始时间:" style="width:30%;display: inline-block;">
                        <input
                            :value="formData.starttime |formatDateStr('yyyy-MM-dd') "
                            type="text"
                            readonly
                        >
                    </el-form-item>
                    <el-form-item label="领取结束时间:" style="margin-left:80px; width:30%;display: inline-block;">
                        <input
                            :value="formData.endtime |formatDateStr('yyyy-MM-dd') "
                            type="text"
                            readonly
                        >
                    </el-form-item>

                </el-form-item>

                <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">
                    <el-form-item label="使用开始时间:" style="width:30%;display: inline-block;">
                        <input
                            :value="formData.usestarttime |formatDateStr('yyyy-MM-dd') "
                            type="text"
                            readonly
                        >
                    </el-form-item>
                    <el-form-item label="使用结束时间:" style="margin-left:80px; width:30%;display: inline-block;">
                        <input
                            :value="formData.useendtime |formatDateStr('yyyy-MM-dd') "
                            type="text"
                            readonly
                        >
                    </el-form-item>
                </el-form-item>

                <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">

                    <el-form-item label="发放形式:" style="width:30%;display: inline-block;">
                        <!--  <input v-model="formData.usemodality" type="text" readonly>-->
                        <span v-if="formData.usemodality===0">普通</span>
                        <span v-if="formData.usemodality===1">注册</span>
                    </el-form-item>
                    <el-form-item label="发放数量:" style="margin-left:80px; width:30%;display: inline-block;">
                        <input v-model="formData.discountnum" type="text" readonly>
                    </el-form-item>

                </el-form-item>

                <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">

                    <el-form-item label="已领取数量:" style="width:30%;display: inline-block;">
                        <input v-model="formData.hasget" type="text" readonly>
                        <!-- <span>{{formData.hasget}}</span>-->
                    </el-form-item>
                    <el-form-item label="已使用数量:" style="margin-left:80px; width:30%;display: inline-block;">
                        <input v-model="formData.hasuse" type="text" readonly>
                    </el-form-item>

                </el-form-item>
                <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">
                    <span>可用商品</span>
                </el-form-item>
                <el-form-item style="border-bottom:1px solid #ebeef5;" label-width="0px">
                    <div>
                        <!--查询条件start --111s-->
                        <el-form :inline="true" :model="query" class="query-form" size="small">

                            <el-form-item class="query-form-item">
                                <el-input
                                    v-model="query2.commodityname"
                                    placeholder="商品名称/ID/店铺/品牌"
                                    prefix-icon="el-icon-search"
                                    @keyup.enter.native="onSubmit2"
                                    clearable
                                ></el-input>
                            </el-form-item>

                            <el-form-item>
                                <el-button type="primary" icon="el-icon-refresh" @click="onRest2"></el-button>
                                <el-button type="primary" icon="el-icon-search" @click="onSubmit2">查询</el-button>
                            </el-form-item>

                            <el-form-item>

                                <!--分类-->
                                <el-form-item label="一级分类">
                                    <el-select v-model="query2.topcategoryid" placeholder="请选择" :change="topchange1()">
                                        <el-option
                                            v-for="(item,index) in category"
                                            :key="index"
                                            :label="item.topcategoryname"
                                            :value="item.topcategoryid">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="二级分类">
                                    <el-select v-model="query2.secondarycategoryid" placeholder="请选择" clearable
                                               :change="secondchange1()">
                                        <el-option
                                            v-for="(item,index) in busCommoditySecondaryCategoryList"
                                            :key="index"
                                            :label="item.secondarycategoryname"
                                            :value="item.secondarycategoryid">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="三级分类">
                                    <el-select v-model="query2.thirdcategoryid" placeholder="请选择" clearable>
                                        <el-option
                                            v-for="(item,index) in busCommodityThirdCategoryList"
                                            :key="index"
                                            :label="item.thirdcategoryname"
                                            :value="item.thirdcategoryid">
                                        </el-option>
                                    </el-select>
                                </el-form-item>

                            </el-form-item>

                        </el-form>

                    </div>

                    <!--列表start --222s-->
                    <el-table
                        ref="multipleTable"
                        v-loading="loading"
                        :data="looklist"
                        :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
                        border
                    >
                        <el-table-column label="商品ID" prop="commodityid" width="80" align="center"/>

                        <el-table-column label="商品图片" prop="commodityicon" align="center" width="200">
                            <template slot-scope="scope">
                                <el-popover v-if="scope.row.commodityicon" placement="right" trigger="hover">
                                    <img :src="scope.row.commodityicon" style="width:400px;border-radius:3px;">
                                    <img
                                        slot="reference"
                                        :src="scope.row.commodityicon"
                                        style="max-height: 80px;max-width: 50px;border-radius:5px;"
                                    >
                                </el-popover>
                                <span v-else>-</span>
                            </template>
                        </el-table-column>

                        <el-table-column label="商品名称" prop="commodityname" align="center"/>
                        <el-table-column label="一级分类" prop="topcategoryname" align="center"/>
                        <el-table-column label="二级分类" prop="secondarycategoryname" align="center"/>
                        <el-table-column label="三级分类" prop="thirdcategoryname" align="center"/>

                    </el-table>

                    <!--分页模块start-->
                    <el-pagination
                        class="pagination-container"
                        background
                        :page-size="query2.pageSize"
                        @size-change="handleSizeChange1"
                        @current-change="handleCurrentChange1"
                        layout="total,sizes,prev, pager, next, jumper"
                        :current-page="query2.currentPage"
                        :page-sizes="[10, 20, 30, 50]"
                        :total="totalNumber1"
                    ></el-pagination>
                    <!--分页模块end-->
                </el-form-item>

            </el-form>
        </el-dialog>

    </div>
</template>
<script>
    import {
        getList,
        delBusDiscount,
        addBusDiscount,
        getCategory,
        getGoodList,
        userlist,
        givediscount
    } from "../../api/coupon/coupon.js";
    import getGoods from "../../components/goods/getGoods.vue";
    /*用作表单的数据初始化*/
    const formJson = {
        discounttype: "",
        denomination: "", //面额
        quota: "", //限额
        starttime: "", //领取开始时间
        endtime: "", //领取结束时间
        usetimetype: "", //0：绝对时间  1：相对时间
        usestarttime: "", //有效开始时间
        useendtime: "", //有效开始时间
        delaydays: 0,//相对时间
        discountnum: 0,//发放数量
        usemodality: "0",//发放形式
        scopeofuse: 0,//使用范围 0：全品  1：指定类品  2：指定酒品

        topcategoryid: "", //一级
        secondarycategoryid: "",//二级
        thirdcategoryid: "",//三级
        categoryids: "",//分类id集合
        commodityids: "", //商品id集合
        categorytext: ""//分类json

    };

    export default {
        components: {
            getGoods
        },
        data() {

            return {
                pickerOptions: {//快速选择日期
                    shortcuts: [
                        {
                            text: "最近一周",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 7
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近一个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 30
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近三个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 90
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        },
                        {
                            text: "最近六个月",
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(
                                    start.getTime() - 3600 * 1000 * 24 * 180
                                );
                                picker.$emit("pick", [start, end]);
                            }
                        }
                    ]
                },

                query: {//查询条件
                    discountid: "",
                    currentPage: 1,
                    pageSize: 10,
                },
                query2: {//查看查询条件
                    content: "",
                    commodityname: "",
                    commodityids: "", //id集合
                    cid: "",//分类
                    currentPage: 1,
                    pageSize: 10,
                    topcategoryid: "", //一级
                    secondarycategoryid: "",//二级
                    thirdcategoryid: ""//三级
                },
                detailVisible: false,
                formName: null,
                formMap: {
                    add: "添加",
                    edit: "编辑",
                    detail: "详情"
                },
                category: [],//分类列表
                busCommoditySecondaryCategoryList: [], //二级
                busCommodityThirdCategoryList: [],//三级
                mchecked: false,
                createTime: [],//选择日期时需要的model
                createTime1: [],//选择日期时需要的model
                list: [],//列表集合
                mlist: [],//添加分类集合
                looklist: [],//查看列表
                commodityids: "",
                totalNumber: 0,//分页总页数
                totalNumber1: 0,//查看分页总页数
                userVisible: false,
                loading: true,//列表加载
                allLoding: false,//全屏加载
                formSumbitLoding: false,//表单提交加载
                cancelToggle: false,//列表是否全选
                multipleSelection: [], //多选集合
                dialogAddOrEdit: false,//新增或编辑弹框开关
                dialogAddOrEditName: "",//新增或编辑弹框名字
                formData: formJson,//新增或修改的对象
                rules: {//表单校验
                    discounttype: {
                        required: true,
                        message: "请输入优惠券类型",
                        trigger: "blur"
                    },

                    denomination: {
                        required: true,
                        message: "请输入面额",
                        trigger: "blur"
                    },
                    quota: {
                        required: true,
                        message: "请输入限额",
                        trigger: "blur"
                    },
                    starttime: {
                        required: true,
                        message: "请输入领取开始时间",
                        trigger: "blur"
                    },
                    endtime: {
                        required: true,
                        message: "请输入领取结束时间",
                        trigger: "blur"
                    },
                    discountnum: {
                        required: true,
                        message: "请输入发放数量",
                        trigger: "blur"
                    },
                    usetimetype: {
                        required: true,
                        message: "请输入时间类型",
                        trigger: "blur"
                    },
                    usemodality: {
                        required: true,
                        message: "请输入发放形式",
                        trigger: "blur"
                    },

                },
                userloading:false,
                dialogUser: false,
                userRules: {},
                userlist: [],
                checklist: [],
                query3: {//查询条件
                    content:"",
                    discountid: "",
                    currentPage: 1,
                    pageSize: 10,
                },
                totalNumber3: 0,
                ids: [],
                discountid: "",
            };
        },


        methods: {
            //选择用户
            selectids(ids, v, name) {
                this.userVisible = v;
                this.formData.commodityid = ids;
                this.commodityids = ids;
                this.commodityname = name;
                this.formData.scopeofuse = 2;
                this.mlist = [];
                this.formData.categoryid = "";
                this.formData.categorytext = "";

            },
            //获得分类
            goodCategory() {
                console.info(this.formData.item)
                let categoryids = null;
                let scategoryids = "";
                let name = null;
                this.formData.scopeofuse = 1;
                this.formData.commodityids = "";

                if (this.formData.topcategoryid) {
                    categoryids = this.formData.topcategoryid;
                    let ca = this.category
                    for (let i = 0; i < ca.length; i++) {
                        if (ca[i].topcategoryid === this.formData.topcategoryid) {
                            name = ca[i].topcategoryname;
                        }
                    }

                }
                if (this.formData.secondarycategoryid) {
                    categoryids = categoryids + "," + this.formData.secondarycategoryid

                    let bc = this.busCommoditySecondaryCategoryList
                    for (let i = 0; i < bc.length; i++) {
                        if (bc[i].secondarycategoryid === this.formData.secondarycategoryid) {
                            name = name + "," + bc[i].secondarycategoryname;
                        }
                    }

                }
                if (this.formData.thirdcategoryid) {
                    categoryids = categoryids + "," + this.formData.thirdcategoryid;
                    scategoryids = this.formData.thirdcategoryid;
                    let bcc = this.busCommodityThirdCategoryList
                    for (let i = 0; i < bcc.length; i++) {
                        if (bcc[i].thirdcategoryid === this.formData.thirdcategoryid) {
                            name = name + "," + bcc[i].thirdcategoryname;
                        }
                    }
                }
                if (categoryids != null) {
                    if (this.formData.categoryids != "") {
                        this.formData.categoryids = this.formData.categoryids + "," + scategoryids;
                        this.formData.categorytext = this.formData.categorytext + "," + name;
                    } else {
                        this.formData.categoryids = scategoryids;
                        this.formData.categorytext = name;
                    }


                    var row = {};
                    row.id = categoryids;
                    row.name = name;
                    // alert(row.toString())
                    var flag = false;
                    for (let i = 0; i < this.mlist.length; i++) {
                        if (this.mlist[i].id === row.id) {
                            flag = true;
                        }
                    }
                    if (!flag) {
                        this.mlist.push(row)
                    }
                } else {
                    alert("没有添加选项")
                }

            },
            goodadd() {
                this.userVisible = true;
            },
            //相对绝对时间
            seltime() {
                // alert(this.formData.usetimetype)
                if (this.formData.usetimetype === 0) {
                    this.formData.delaydays = 0;
                }
                if (this.formData.usetimetype === 1) {
                    this.formData.usestarttime = "";
                    this.formData.useendtime = "";
                }
            },
            //首次公开
            changes() {
                // alert("1233--"+this.formData.usemodality)
            },
            //商品全选
            changecheck() {
                // alert("1233--"+this.formData.usemodality)
                if (this.mchecked) {
                    this.formData.scopeofuse = 0;
                    this.commodityids = "";
                } else {
                    this.formData.scopeofuse = 2
                }

            },

            //一级
            topchange() {
                for (var i = 0; i < this.category.length; i++) {
                    if (this.category[i].topcategoryid == this.formData.topcategoryid) {
                        this.busCommoditySecondaryCategoryList = this.category[i].busCommoditySecondaryCategoryList;
                        break;
                    }
                }
            },
            //二级
            secondchange() {
                for (var i = 0; i < this.busCommoditySecondaryCategoryList.length; i++) {
                    if (this.busCommoditySecondaryCategoryList[i].secondarycategoryid == this.formData.secondarycategoryid) {
                        this.busCommodityThirdCategoryList = this.busCommoditySecondaryCategoryList[i].busCommodityThirdCategoryList;
                        break;
                    }
                }
            },
            //一级
            topchange1() {
                for (var i = 0; i < this.category.length; i++) {
                    if (this.category[i].topcategoryid == this.query2.topcategoryid) {
                        this.busCommoditySecondaryCategoryList = this.category[i].busCommoditySecondaryCategoryList;
                        break;
                    }
                }
            },
            //二级
            secondchange1() {
                for (var i = 0; i < this.busCommoditySecondaryCategoryList.length; i++) {
                    if (this.busCommoditySecondaryCategoryList[i].secondarycategoryid == this.query2.secondarycategoryid) {
                        this.busCommodityThirdCategoryList = this.busCommoditySecondaryCategoryList[i].busCommodityThirdCategoryList;
                        break;
                    }
                }
            },


            //获得分类
            getAllCategory() {
                this.loading = true;
                getCategory()
                    .then(response => {
                        if (response.code) {
                            this.$message.error(response.message);
                        }
                        let data = response.data || [];
                        this.category = data;
                        setTimeout(() => {
                            this.loading = false;
                        }, 0.3 * 1000);
                    })
                    .catch(() => {
                        this.loading = false;
                        this.list = [];
                        this.totalNumber = 0;
                    });
            },


            /*获取列表事件*/
            getList() {
                this.loading = true;
                getList(this.query).then(response => {
                    if (response.code != 0) {
                        this.$message.error(response.message);
                        return false;
                    }

                    this.list = response.data.list || [];

                    this.totalNumber = response.data.totalNumber || 0;
                    setTimeout(() => {
                        this.loading = false;
                    }, 0.3 * 1000);
                }).catch(() => {
                    this.loading = false;
                    this.list = [];
                })
            },

            /*新增或者编辑提交事件*/
            formSumbit3() {
                //alert(JSON.stringify(this.checklist));
                var uids = this.checklist.map(item => item).join(); //获取所有选中行的id组成的字符串，以逗号分隔
                //表单校验通过
                this.formSumbitLoding = true;
                var params = new URLSearchParams();
                params.append("ids", uids);
                params.append("discountid", this.discountid);
                givediscount(params).then(response => {
                    this.dialogUser=false;
                    this.formLoading = false;
                    if (response.code != 0) {
                        this.$message.error(response.message);
                        this.formSumbitLoding = false;
                        return false;
                    }
                    this.checklist=[];
                    this.$message.success("操作成功");
                    this.userlist = [];
                    this.formSumbitLoding = false;
                    this.dialogUser = false;

                }).catch(() => {
                    this.formSumbitLoding = false;
                });

            },


            /*新增或者编辑提交事件*/
            formSumbit() {
                //表单校验通过
                this.$refs["ruleForm"].validate(valid => {
                    if (valid) {
                        this.formSumbitLoding = true;
                        this.formData.commodityids = this.commodityids;
                        console.info(this.formData);
                        var params = new URLSearchParams(this.formData);
                        addBusDiscount(params).then(response => {
                            this.formLoading = false;
                            if (response.code != 0) {
                                this.$message.error(response.message);
                                this.formSumbitLoding = false;
                                return false;
                            }
                            this.$message.success("操作成功");
                            this.formData = {};
                            this.mlist = [];
                            this.createTime = [];
                            this.createTime1 = [];
                            this.formSumbitLoding = false;
                            this.dialogAddOrEdit = false;
                            // 加载表格数据
                            this.getList();
                            // 清空表单
                            this.$refs["dataForm"].resetFields();

                        }).catch(() => {
                            this.formSumbitLoding = false;
                        });

                    }
                });
                //new URLSearchParams(this.query)  提交数据格式不正确时可以转一下
            },

            /*列表查询条件事件*/
            onSubmit() {
                this.query.currentPage = 1;
                this.$router.push({
                    path: "",
                    query: this.query
                });
                this.getList();
            },
            /*列表查询条件事件*/
            onSubmit2() {
                this.query2.currentPage = 1;
                this.$router.push({
                    path: "",
                    query2: this.query2
                });
                this.getGoods();
            },

            /*刷新*/
            onRest() {
                this.$router.push({
                    path: ""
                });
                //刷新事件需要重置查询条件
                this.createTime = [];
                this.query = {
                    currentPage: 1,
                    pageSize: 10,
                };
                this.getList();
            },

            /*刷新查看*/
            onRest2() {
                this.$router.push({
                    path: ""
                });
                //刷新事件需要重置查询条件
                this.query2 = {
                    currentPage: 1,
                    pageSize: 10,
                };
                this.getGoods();
            }, /*刷新查看*/
            onRest4() {
                this.checklist=[];
                this.$router.push({
                    path: ""
                });
                //刷新事件需要重置查询条件
                this.query3 = {
                    currentPage: 1,
                    pageSize: 10,
                };
                this.getUserList();
            },
            /*刷新查看*/
            onRest3() {
                this.$router.push({
                    path: ""
                });
                //刷新事件需要重置查询条件
                this.query3 = {
                    currentPage: 1,
                    pageSize: 10,
                };
                this.getGoods();
            },
            //赠送优惠券
            showForm(index, row) {
                if (row !== null) {
                    this.getUserList();
                    this.discountid = row.discountid;
                    this.dialogUser = true;

                }
            },
            getUserList() {
                this.userloading = true;
                userlist(this.query3).then(response => {
                    if (response.code != 0) {
                        this.$message.error(response.message);
                        return false;
                    }
                    this.userlist = response.data.list || [];
                    this.totalNumber3 = response.data.totalNumber || 0;
                    setTimeout(() => {
                        this.userloading = false;
                    }, 0.3 * 1000);
                }).catch(() => {
                    this.userloading = false;
                    this.userlist = [];
                })
            },


            //显示 查看弹框
            detailForm(index, row) {
                if (row !== null) {
                    console.info(row)
                    this.detailVisible = true;
                    this.formData = Object.assign({}, row);
                    this.formName = "detail";
                    this.query2.commodityids = row.commodityids;
                    this.query2.cid = row.categoryids;
                    this.$router.push({
                        path: "",
                        query2: this.query2
                    });
                    //  alert( this.query2.comids);
                    this.getGoods();
                    this.getAllCategory();
                }
            },
            //获得查看商品列表
            getGoods() {
                /* var params = new URLSearchParams();
                 params.append("ids", ids);*/
                console.info(this.query2)
                getGoodList(this.query2)
                    .then(response => {
                        this.loading = false;
                        if (response.code) {
                            this.$message.error(response.message);
                            return false;
                        }
                        this.looklist = response.data.list;
                        this.totalNumber1 = response.data.totalNumber || 0;
                        //this.$message.success("查询成功");
                        // 刷新数据
                        //this.list.splice(index, 1);

                    })
                    .catch(() => {
                        this.loading = false;
                    });
            },
            // 隐藏详情弹框
            hideDetailForm() {
                // 更改值
                this.detailVisible = !this.detailVisible;
                return true;
            },
            /*显示 -新增或者编辑弹框*/
            showDialogAddOrEdit(index, row) {
                this.dialogAddOrEdit = true;
                this.formData = Object.assign({}, formJson);//将弹框内表单内容初始化
                if (row !== null) {
                    //如果row不为空，说明是修改，因为row是修改时携带过来此列的所有信息
                    this.formData = Object.assign({}, row);//修改则将列内容深拷贝到表单内容中
                    this.dialogAddOrEditName = "编辑";
                } else {
                    this.createTime = [];
                    this.createTime1 = [];
                    this.dialogAddOrEditName = "新增";
                }
                this.getAllCategory();
            },

            /*隐藏 -新增或编辑弹框*/
            hideDialogUser() {
                this.dialogUser = false;
                //隐藏弹框时需要清除弹框内容
                if (this.$refs["userRuleForm"]) {
                    this.$refs['userRuleForm'].resetFields();//清除formData表单
                    this.$refs["userRuleForm"].clearValidate();//清除表单验证
                }
                //如果上传文件，还需要清除文件列表
            },

            /*隐藏 -新增或编辑弹框*/
            hideDialogAddOrEdit() {
                this.dialogAddOrEdit = false;

                //隐藏弹框时需要清除弹框内容
                if (this.$refs["ruleForm"]) {
                    this.$refs['ruleForm'].resetFields();//清除formData表单
                    this.$refs["ruleForm"].clearValidate();//清除表单验证
                }
                //如果上传文件，还需要清除文件列表
            },

            //查看
            /*点击页数*/
            handleCurrentChange1(val) {
                this.query2.currentPage = val;
                this.getGoods();
            },
            //查看
            /*选择每页条数【10,20,30,40,50】*/
            handleSizeChange1(val) {
                this.query2.pageSize = val;
                this.getGoods();
            },
            //查看
            /*点击页数*/
            handleCurrentChange3(val) {
                this.query3.currentPage = val;
                this.getUserList();
            },
            //查看
            /*选择每页条数【10,20,30,40,50】*/
            handleSizeChange3(val) {
                this.query3.pageSize = val;
                this.getUserList();
            },

            /*点击页数*/
            handleCurrentChange(val) {
                this.query.currentPage = val;
                this.getList();
            },

            /*选择每页条数【10,20,30,40,50】*/
            handleSizeChange(val) {
                this.query.pageSize = val;
                this.getList();
            },

            /*取消全选事件*/
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },

            /*列表复选框选择事件*/
            handleSelectionChange(val) {
                this.multipleSelection = val;
                if (val == "") {
                    this.cancelToggle = false;
                    return;
                }
                this.cancelToggle = true;
            },

            /*全选删除事件*/
            delGroup() {
                console.log(this.multipleSelection)
                var ids = this.multipleSelection.map(item => item.discountid).join(); //获取所有选中行的id组成的字符串，以逗号分隔
                if (ids == "") {
                    this.$message({
                        message: "请先选择",
                        type: "warning"
                    });
                    return;
                }
                this.handleDel(ids);
            },
            //删除添加
            mhandleDel(id) {

                for (let i = 0; i < this.mlist.length; i++) {
                    if (this.mlist[i].id === id) {
                        this.mlist.splice(i, 1);
                    }
                }
            },
            /*单击删除事件*/
            handleDel(ids) {
                if (ids) {
                    this.$confirm("确认要删除吗?", "提示", {
                        type: "warning"
                    })
                        .then(() => {

                            this.loading = true;
                            var params = new URLSearchParams();
                            params.append("ids", ids);
                            delBusDiscount(params)
                                .then(response => {
                                    this.loading = false;
                                    if (response.code) {
                                        this.$message.error(response.message);
                                        return false;
                                    }
                                    this.$message.success("删除成功");
                                    // 刷新数据
                                    //this.list.splice(index, 1);
                                    this.getList();
                                })
                                .catch(() => {
                                    this.loading = false;
                                });
                        })
                        .catch(() => {
                            this.$message.warning("已取消");
                        });
                }
            },

            /*日期选择事件*/
            dateChange(val) {
                if (val == null) {
                    this.formData.starttime = "";
                    this.formData.endtime = "";
                } else {
                    this.formData.starttime = val[0];
                    this.formData.endtime = val[1];

                }

            },
            /*日期选择事件*/
            dateChange1(val) {
                if (val == null) {
                    this.formData.usestarttime = "";
                    this.formData.useendtime = "";
                } else {
                    this.formData.usestarttime = val[0];
                    this.formData.useendtime = val[1];

                }

            },


        }, created() {
            this.getList();
        }
    }

</script>
